﻿// =================================================================== 
// 业务逻辑层(GDIT.BLL)
//====================================================================
// 文件：BCollegeInformationArticle.cs
// 项目名称：学院网站
// 创建时间：2012-08-12
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：校园资讯信息操作逻辑
// ===================================================================
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using GDIT.Base.LogHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Model;

namespace GDIT.BLL
{
    public class BCollegeInformationArticle
    {
        private Pattern.DALAbstractFactory dataFactory = DataProvider.defaultProvider;

        /// <summary>
        /// 管理员展示页面
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectAllColegeByAdmin()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectAllColegeByAdmin();
        }

        /// <summary>
        /// 新增加一篇校园资讯
        /// </summary>
        /// <param name="bulletin">需要增加的校园资讯对象</param>
        /// <returns>1：新增成功  0：新增失败</returns>
        public bool InsertCollegeInformationArticle(Mtb_Users user)
        {
            Logger.Info(String.Format("新增校园资讯标题[{0}]", user.UserName));
            int result = dataFactory.DALDusersProvider.AddUserCollegeArticle(user);
            if (result == 1)
            {
                Logger.Info("Insert success");
                return true;
            }
            else
            {
                Logger.Info("Insert false");
                return false;
            }
        }

        /// <summary>
        /// 根据关键字查询并返回校园资讯集合
        /// </summary>
        /// <param name="keyWord">输入的关键字</param>
        /// <returns></returns>
        public string[] SelectCollegeByKeyWord(string keyWord, int displaycount)
        {
            XPCollection xp = dataFactory.DALCollegeInformationArticleProvider.SelectCollegeByKeyWord(keyWord);
            List<string> results = new List<string>(displaycount);
            foreach (Mtb_CollegeInformationArticle word in xp)
            {
                results.Add(word.Title);
            }
            return results.ToArray();
        }

        /// <summary>
        /// 删除一篇校园资讯
        /// </summary>
        /// <param name="bulletin">需要删除的校园资讯对象</param>
        /// <returns>1：删除成功  0：删除失败</returns>
        public bool DeleteCollegeInformationArticle(int id)
        {
            Logger.Info(String.Format("校园资讯ID[{0}]", id));
            int result =  dataFactory.DALCollegeInformationArticleProvider.DeleteCollegeInformationArticle(id);
            if (result == 1)
            {
                Logger.Info("Delete success");
                return true;
            }
            else
            {
                Logger.Info("Delete false");
                return false;
            }
        }

        /// <summary>
        /// 更新一篇校园资讯标题和内容
        /// </summary>
        /// <param name="bulletin">需要更新的校园资讯的对象</param>
        /// <returns>1：删除成功  0：删除失败</returns>
        public bool UpdateCollegeInformationArticle(Mtb_CollegeInformationArticle bulletin)
        {
            Logger.Info(String.Format("校园资讯标题[{0}]", bulletin.Title));
            int result =  dataFactory.DALCollegeInformationArticleProvider.UpdateCollegeInformationArticle(bulletin);
            if (result == 1)
            {
                Logger.Info("Update success");
                return true;
            }
            else
            {
                Logger.Info("Update false");
                return false;
            }
        }

        /// <summary>
        /// 增加校园资讯的点击率
        /// </summary>
        public int AddCollegeInformationArticleCounter(int id)
        {
            return dataFactory.DALCollegeInformationArticleProvider.AddCollegeInformationArticleCounter(id);
        }

        /// <summary>
        /// 查询所有非置顶，重点，内部的校园资讯列表
        /// </summary>
        /// <returns>返回所有的校园资讯列表</returns>
        public XPCollection SelectAllCollegeInformationArticle()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectAllCollegeInformationArticle();
        }

        /// <summary>
        /// 查询所有非置顶，重点，是内部的校园资讯列表
        /// </summary>
        /// <returns>返回所有的校园资讯列表</returns>
        public XPCollection SelectAllInternalCollegeInformationArticle()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectAllInternalCollegeInformationArticle();
        }

        /// <summary>
        /// 根据校园资讯Id查询并返回校园资讯单一记录
        /// </summary>
        /// <param name="id">需要查询的校园资讯Id</param>
        /// <returns>返回校园资讯单一记录</returns>
        public Mtb_CollegeInformationArticle SelectCollegeInformationArticleById(int id)
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectCollegeInformationArticleById(id);
        }

        /// <summary>
        /// 根据部门名称查询并返回该部门的所有校园资讯列表
        /// </summary>
        /// <param name="name">需要查询的部门名称</param>
        /// <returns>返回该部门的校园资讯列表</returns>
        public XPCollection SelectCollegeInformationArticleByDepartment(string departmentName)
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectCollegeInformationArticleByDepartment(departmentName);
        }

        /// <summary>
        /// 显示置顶校园资讯
        /// </summary>
        /// <returns>返回置顶校园资讯列表</returns>
        public XPCollection SelectCollegeInformationArticleByTop()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectCollegeInformationArticleByTop();
        }

        /// <summary>
        /// 显示重点校园资讯
        /// </summary>
        /// <returns>返回重点校园资讯列表</returns>
        public XPCollection SelectCollegeInformationArticleByImportant()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectCollegeInformationArticleByImportant();
        }

        /// <summary>
        /// 显示内部重点学院资讯
        /// </summary>
        /// <returns>返回重点公告列表</returns>
        public XPCollection SelectInternalCollegeInformationArticleByImportant()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectInternalCollegeInformationArticleByImportant();
        }

        /// <summary>
        /// 显示内部置顶校园资讯
        /// </summary>
        /// <returns>返回置顶公告列表</returns>
        public XPCollection SelectInternalCollegeInformationArticleByTop()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectInternalCollegeInformationArticleByTop();
        }

        /// <summary>
        /// 设置校园资讯为内部显示
        /// </summary>
        /// <returns>返回内部校园资讯列表</returns>
        public bool UpdateCollegeInformationArticleByInternal(Mtb_CollegeInformationArticle college)
        {
            Logger.Info(String.Format("校园概况标题[{0}]", college.Title));
            int result = dataFactory.DALCollegeInformationArticleProvider.SelectCollegeInformationArticleByInternal(college);
            if (result == 1)
            {
                Logger.Info("Update success");
                return true;
            }
            else
            {
                Logger.Info("Update false");
                return false;
            }
        }

        /// <summary>
        /// 设置校园资讯为重点显示
        /// </summary>
        /// <returns>1：更新成功  0：更新失败</returns>
        public bool UpdateCollegeInformationArticleByImportant(Mtb_CollegeInformationArticle college)
        {
            Logger.Info(String.Format("校园概况标题[{0}]", college.Title));
            int result = dataFactory.DALCollegeInformationArticleProvider.UpdateCollegeInformationArticleByImportant(college);
            if (result == 1)
            {
                Logger.Info("Update success");
                return true;
            }
            else
            {
                Logger.Info("Update false");
                return false;
            }
        }

        /// <summary>
        /// 设置校园资讯为置顶显示
        /// </summary>
        /// <returns>1：更新成功  0：更新失败</returns>
        public bool UpdateCollegeInformationArticleByTop(Mtb_CollegeInformationArticle college)
        {
            Logger.Info(String.Format("校园概况标题[{0}]", college.Title));
            int result = dataFactory.DALCollegeInformationArticleProvider.UpdateCollegeInformationArticleByTop(college);
            if (result == 1)
            {
                Logger.Info("Update success");
                return true;
            }
            else
            {
                Logger.Info("Update false");
                return false;
            }
        }

        /// <summary>
        /// 显示首页的校园资讯内容
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectCollege()
        {
            XPCollection result = new XPCollection(typeof(Mtb_CollegeInformationArticle));
            XPCollection xp = dataFactory.DALCollegeInformationArticleProvider.SelectCollegeInformationArticleByTopAndImportant();
            for (int i = 0; i <= 5; i++)
            {
                result.Add(xp[i]);
            }
            return result;
        }

        /// <summary>
        /// 显示内部首页的校园资讯内容
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectInternalCollege()
        {
            XPCollection result = new XPCollection(typeof(Mtb_CollegeInformationArticle));
            XPCollection xp =  dataFactory.DALCollegeInformationArticleProvider.SelectInternalBulletinArticleByTopAndImportant();
            for (int i = 0; i <= 5; i++)
            {
                result.Add(xp[i]);
            }
            return result;
        }

        /// <summary>
        /// 显示校园资讯内容
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectCollegeInformationArticleByTopAndImportant()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectCollegeInformationArticleByTopAndImportant();
        }

        /// <summary>
        /// 显示内部校园资讯内容
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectInternalCollegeInformationArticleByTopAndImportant()
        {
            return dataFactory.DALCollegeInformationArticleProvider.SelectInternalBulletinArticleByTopAndImportant();
        }
    }
}
